﻿<!DOCTYPE html>
<!--试题管理编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">
            <el-row>
                <el-col class="head-tool">
                    <el-button type="primary" @click="UserInput('tj')">{{col.btnAdd}}</el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{TestQuestions.TestQuestionsContent+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.testQuestionsContent"
                                    autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>


                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{TestQuestions.TestQuestionsType+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.testQuestionsType" slot="suffix"
                                    :placeholder="TestQuestions.TestQuestionsType">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in TestQuestionsTypeList" :label="item.value"
                                        :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{TestQuestions.CoursewareType+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.cbsCourseId" slot="suffix"
                                    :placeholder="TestQuestions.CoursewareType">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in CoursewareType" :label="item.trainingCoursewareName" :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{TestQuestions.DegreeOfDifficulty+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.degreeOfDifficulty" slot="suffix"
                                    :placeholder="TestQuestions.DegreeOfDifficulty">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in DegreeOfDifficultyList" :label="item.value"
                                        :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.numberOfOptions" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{TestQuestions.NumberOfOptions+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>

            <el-row>
                <el-col span="24">
                    <el-form-item label="选项： " style="text-align:left;">
                    </el-form-item>
                </el-col>
                <el-col span="24">
                    <el-table :data="Form.cbS_QuestionsOptions" border stripe style="width:100%">
                        <el-table-column prop="optionName" :label="TestQuestionsOption.OptionName" width="180">
                        </el-table-column>
                        <el-table-column prop="optionComment" :label="TestQuestionsOption.OptionComment" width="180">
                        </el-table-column>
                        <el-table-column prop="" align="center" label="答案">
                            <template slot-scope="scope">
                                <el-select @visible-change="visibleChange" @change="handleSelect" size='mini' v-model="scope.row.isAnswer" placeholder="请选择">
                                    <el-option v-for="item in TestQuestionsOptionsList" :key="item.key"
                                               :label="item.value" :value="item.key"></el-option>
                                </el-select>
                            </template>
                        </el-table-column>

                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button @click.native.prevent="deleteRow(scope.$index, Form.cbS_QuestionsOptions)" type="text"
                                           size="small">
                                    移除
                                </el-button>
                            </template>
                        </el-table-column>
                        <el-table-column prop="id" width="1" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span style="display:none;">{{scope.row.id}}</span>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
            <el-row type="flex" justify="end" style=" margin-top:10px">
                <el-form-item>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>-->
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click=" parent.app.ListItem.dialogVisible = false">{{col.btnBack}}
                    </el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <el-dialog title="试题选项" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%" height="80%"
            top="10vh" fullscreen="true">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:90%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                CBSCourseId:'',
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    TestQuestionsContent: '',//"试题内容"
                    TestQuestionsType: '', //试题类型
                    DegreeOfDifficulty: '',//难易程度
                    NumberOfOptions: '',//选项个数
                    Answer: '',//答案
                    editor: '',
                    editorTime: '',
                    cbsCourseId: '',//课件类型
                    CoursewareID: null,//课件类型ID
                    cbS_QuestionsOptions: [],//选项
                    pid: null

                },
                ListItem: ListItem,
                options: [],
                TestQuestionsOptionsList: [{ key: '是', value: '是' },
                    { key: '否', value: '否' }],
                //mydata: TestQuestionsTree,
                TestQuestionsTypeList: [{ key: '单选', value: '单选' },
                    { key: '多选', value: '多选' },
                    { key: '判断', value: '判断' }],//试题类型
                DegreeOfDifficultyList: [{ key: '简单', value: '简单' },
                    { key: '一般', value: '一般' },
                    { key: '困难', value: '困难' },
                    { key: '极难', value: '极难' }],
                CoursewareType: [],
                //表单验证
                rules: {
                    PersonnelName: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(2, 5), message: verification.StringLengthAtoB.m.format(2, 5), trigger: 'blur' }
                    ],
                    ContractorName: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(5, 50), message: verification.StringLengthAtoB.m.format(5, 10), trigger: 'blur' }
                    ],

                },
                delIds: [],
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                handleChange: function (value) {
                    console.log(value);
                },
                handleSelect: function (ev) {
                    console.log(ev);
                },
                deleteRow: function (index, rows) {
                    var mythis = this; if (mythis.Form.cbS_QuestionsOptions[index].id == null || mythis.Form.cbS_QuestionsOptions[index].id == "" || mythis.Form.cbS_QuestionsOptions[index].id == undefined) {
                        rows.splice(index, 1);
                    } else {
                        mythis.delIds.push(mythis.Form.cbS_QuestionsOptions[index].id);
                        rows.splice(index, 1);
                       
                    }
                },
                GetPageData: function (currentIndex) { },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            //onSubmitForm(this, '/api/CBS_Questions/Save', mythis.Form);
                            if (mythis.Form.testQuestionsContent == null || mythis.Form.testQuestionsContent == "" || mythis.Form.testQuestionsContent == undefined) {
                                alert('请输入试题内容');
                                return false;
                            }
                            if (mythis.Form.testQuestionsType == null || mythis.Form.testQuestionsType == "" || mythis.Form.testQuestionsType == undefined) {
                                alert('请选择试题类型');
                                return false;
                            }
                            if (mythis.Form.cbsCourseId == null || mythis.Form.cbsCourseId == "" || mythis.Form.cbsCourseId == undefined) {
                                alert('请选择课件类型');
                                return false;
                            }
                            if (mythis.Form.degreeOfDifficulty == null || mythis.Form.degreeOfDifficulty == "" || mythis.Form.degreeOfDifficulty == undefined) {
                                alert('请选择难易程度');
                                return false;
                            }
                            if (mythis.Form.numberOfOptions == null || mythis.Form.numberOfOptions == "" || mythis.Form.numberOfOptions == undefined ) {
                                alert('请输入选项个数');
                                return false;
                            }
                            if (parseInt(mythis.Form.numberOfOptions) != mythis.Form.cbS_QuestionsOptions.length) {
                                alert('选项个数与选项数不符');
                                return false;
                            }
                            if (mythis.Form.cbS_QuestionsOptions == null || mythis.Form.cbS_QuestionsOptions == undefined || mythis.Form.cbS_QuestionsOptions.length == 0) {
                                alert('请添加选项');
                                return false;
                            }
                            var z = 0;
                            if (mythis.Form.testQuestionsType == "多选") {

                            } else {
                               
                                for (var i = 0; i < mythis.Form.cbS_QuestionsOptions.length; i++) {
                                    if (mythis.Form.cbS_QuestionsOptions[i].isAnswer == null || mythis.Form.cbS_QuestionsOptions[i].isAnswer == "") {
                                        mythis.Form.cbS_QuestionsOptions[i].isAnswer = "否";
                                    }
                                    if (mythis.Form.cbS_QuestionsOptions[i].isAnswer == "是") {
                                        z = parseInt(z) + 1;
                                    }
                                }
                                
                            }
                            if (parseInt(z) > 1) {
                                alert(mythis.Form.testQuestionsType + '只可以有一个答案');
                                return false;
                            }


                            myAjax("post", mythis, '/api/CBS_Questions/Save', mythis.Form, function (response1) {
                                var cbsQuestionsId = response1.data; //总体评估考核ID
                                if (mythis.id == null || mythis.id == "" || mythis.id == undefined || mythis.id == "undefined") {

                                } else {
                                    cbsQuestionsId = mythis.id;
                                }

                                //删除子集
                                if (mythis.delIds.length > 0) {
                                    myAjax("post", this, '/api/CBS_QuestionsOptions/DeleteMuti', mythis.delIds, function (response) {
                                        mythis.delIds = [];
                                    });
                                }
                                showMessage(msg.OperatingOk, 'success');
                                parent.app.ListItem.dialogVisible = false;
                            });
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/CBS_Questions/get?id=' + this.id);
                },

                UserInput: function (val, id) { DialogShow(this, val, "TestQuestionsOptionInput.html", id); },
                //初始化课件
                getClassList: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/CBS_Course/GetList', { model: { PId: null }, offset: 0, limit: 100 }, function (response) {
                        mythis.CoursewareType = response.data.pageData;

                        //console.log(response.data.pageData);
                    }, false);
                },
            },
            mounted: function () {
                //var list = getDicDataArray(['50', '28', '55', '27']);
                //this.TestQuestionsTypeList = getDicData('28', list);
                //this.DegreeOfDifficultyList = getDicData('55', list);
                //this.TestQuestionsOptionsList = getDicData('50', list);
                //this.CoursewareType = getDicData('27', list);
                //this.options = fn(this.mydata, "0");

                this.getClassList();
                this.id = getUrlParam("id");
                this.CBSCourseId = getUrlParam("CBSCourseId");
                this.Form.cbsCourseId = getUrlParam("CBSCourseId");
                this.getData();
            }
        });
    </script>
</body>

</html>